﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Drawing.Drawing2D;

namespace Demo.Classroom
{
    public partial class DemoPrinting : Form
    {
        private PrintDocument printDocument = new PrintDocument();
        public DemoPrinting()
        {
            InitializeComponent();
            printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
        }

        void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            // Xử lí vẽ hình lên giấy
            Graphics graphics = e.Graphics;
            LinearGradientBrush myBrush = new LinearGradientBrush(
                new Point(0, 0),
                new Point(10, 10),
                Color.Blue, Color.Red);
            graphics.DrawString(
                "ACCP1107 - WFC#-I",
                new Font("Arial", 72),
                myBrush,
                00, 00);
        }

        private void pageSetupButton_Click(object sender, EventArgs e)
        {
            // Show lên PageSetupDialog, cấu hình trang in
            pageSetupDialog1.Document = printDocument;
            pageSetupDialog1.ShowDialog();
        }

        private void printButton_Click(object sender, EventArgs e)
        {
            // Show lên hộp thoại PrintDialog, nếu user chọn OK thì in
            printDialog1.Document = printDocument;
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                printDocument.Print(); // -> code sẽ nhảy vô xử lí sự kiện PrintPage
            }

        }
    }
}
